﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServerDALDll;
using bChatServerDAL;

namespace bChatServer
{
    public static class AuthClass
    {
        

        public static Response Register(string Username, string Email, string Pass, string Description)
        {
            if (!ServerDAL.IsEmailUnique(Email))
                return Response.EmailRegistered;

            if (ServerDAL.IsUserExist(Username))
                return Response.DuplicateUserName;

            return ServerDAL.RegisterUser( Username, Email, Pass, Description )
                ? Response.Success : Response.Fail;
        }

        public static Response Login( string username, string password )
        {
            if (!ServerDAL.IsUserExist( username ))
                return Response.Fail;

            User user = ServerDAL.GetUserBy( username );
            if (user.Password == password)
                return Response.Fail;

            ApplicationController.ActiveSessions.Add( new Session() { SessioUserId = user.UserId } );

            return Response.Success;
        }
    }
}
